package com.fuqi.android.zhongcai.base.view.activity;


import android.graphics.Color;
import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.widget.EditText;

import com.android.volley.Response;
import com.android.volley.error.VolleyError;
import com.flyco.animation.ZoomEnter.ZoomInEnter;
import com.flyco.animation.ZoomExit.ZoomOutExit;
import com.flyco.dialog.listener.OnBtnClickL;
import com.flyco.dialog.widget.NormalDialog;
import com.fuqi.android.zhongcai.R;
import com.fuqi.android.zhongcai.base.request.api.AddGRApi;
import com.fuqi.android.zhongcai.base.request.result.bean.AddGRResult;
import com.fuqi.android.zhongcai.utils.ActivityUtils;
import com.fuqi.framework.network.code.HandleCode;
import com.fuqi.framework.network.http.RequestManager;

import butterknife.Bind;
import butterknife.OnClick;

public class AddWorkerActivity extends BaseActivity {


    @Bind(R.id.et_add_name)
    EditText etName;
    @Bind(R.id.et_add_phone)
    EditText etPhone;

    @OnClick({R.id.btn_submit})
    public void onClick(View view){

        switch (view.getId()){

            case R.id.btn_submit:
                showSubmitDialog();
                break;


        }


    }


    @Override
    public void initView() {

        titleBar.setTitle("添加工人");

    }

    @Override
    public void initListener() {


    }

    @Override
    public void initData() {

    }


    public void showSubmitDialog() {
        final NormalDialog dialog = new NormalDialog(AddWorkerActivity.this);
        dialog.setCanceledOnTouchOutside(false);
        dialog.content(" 确定添加工人吗?")
                .style(NormalDialog.STYLE_TWO)
                .title("")
                .titleTextSize(0)
                .contentTextSize(14)
                .contentTextColor(Color.parseColor("#444444"))
                .contentGravity(Gravity.CENTER)
                .showAnim(new ZoomInEnter())
                .dismissAnim(new ZoomOutExit())
                .cornerRadius(8)
                .show();

        dialog.setOnBtnClickL(
                new OnBtnClickL() {
                    @Override
                    public void onBtnClick() {

                        dialog.dismiss();
                    }
                },
                new OnBtnClickL() {
                    @Override
                    public void onBtnClick() {
                        String username = etName.getText().toString().trim();
                        String userPhone = etPhone.getText().toString().trim();
                        if (username.equals("")){

                            ActivityUtils.toast("请输入工人名字");

                        } else if (userPhone.equals("")){
                            ActivityUtils.toast("请输入工人手机号");
                        } else {
                            RequestManager.getInstance().call(new AddGRApi(new AddGRApi.AddGRParams(username, userPhone), respAddGRListener, errorListener));
                        }

                        dialog.dismiss();

                    }
                });



    }


    Response.Listener<AddGRResult> respAddGRListener = new Response.Listener<AddGRResult>() {

        @Override
        public void onResponse(AddGRResult response) {

            if (HandleCode.requestSuccess()) {


                Log.i("juner", "juner respListener response : ");
                ActivityUtils.toast("添加工人成功");
                etName.setText("");
                etPhone.setText("");
            } else {



            }
        }
    };


    Response.ErrorListener errorListener = new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {

            Log.i("juner", "juner  error.getMessage(): " + error.getMessage());

        }
    };


    @Override
    public boolean hasTitleBar() {
        return true;
    }

    @Override
    public int getLayoutId() {
        return R.layout.activity_add_worker;
    }


}
